#ifndef __CHATWINDOW_H__
#define __CHATWINDOW_H__

#include "common/status.h"

#include <QMainWindow>
#include <QWidget>
#include <QVector>
#include <QMap>

class QAction;
class QMenu;
class QTextEdit;
class QPushButton;
class QListWidget;
class QListWidgetItem;
class QVBoxLayout;
class QHBoxLayout;
class QSplitter;
class QPushButton;
class QLabel;

class Chat;
class Friend;

namespace Ui{

enum ChatEvent {
	Join,
	Quit,
	StatusChange
};

class ChatWindow : public QMainWindow {
Q_OBJECT
public:
	ChatWindow(Chat *chat, Friend *me, QWidget *parent);
	~ChatWindow();

public slots:
	void newIncomingMessage(Friend* _friend, const QString& _text);
	void newOutcomingMessage();
	void newEventMessage(ChatEvent event, Friend* _friend);
	void addFriend(Friend* _friend);
	void removeFriend(Friend* _friend);
	void terminate();
	void updateStatusFriend(Friend* _friend);
	void invite();

protected:
	void closeEvent(QCloseEvent *event);

private slots:
	void quit();
	void textChanged();

private:
	QIcon getStatusIcon(Status _status) const;
	void createCentralWidget();

	QMenu *chatMenu;
	QAction *quitChatAction;
	QAction *inviteFriend;

	QTextEdit* editor;
	QTextEdit* display;

	QMenu* friendsMenu;
	QListWidget* friendsList;
	QMap<int, QListWidgetItem*> friendsListItens;
	QPushButton* send;
	QPushButton* addIcon;
	QSplitter* displayFriendsListSplitter;
	QSplitter* editorSendSplitter;
	QSplitter* vsplitter;
	QVBoxLayout* mainLayout;
	QVBoxLayout* friendsVLayout;
	QHBoxLayout* friendsHLayout;
	QLabel* friendsCount;
	
	Chat* chat;
	Friend* me;

	int nFriends;
	bool terminated;

	void updateTitle();

signals:
	void newOutcomingMessage(const QString& _text, Chat *chat);
	void inviteChat(Chat* chat, QString login );
	void quitChat(Chat *chat);
};

}

#endif

